/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package za.co.pas.spaceandtime.model.combo;

import java.util.List;
import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;
import za.co.pas.spaceandtime.constant.STConstant;
import za.co.pas.spaceandtime.data.BedType;
import za.co.pas.spaceandtime.model.ConfigDataModel;
import za.co.pas.spaceandtime.mvc.SpaceAndTimeMVC;

/**
 *
 * @author alabuschagne
 */
public class BedTypeComboModel implements ComboBoxModel
{
    private ConfigDataModel configDataModel = (ConfigDataModel) STConstant.stMVC.getModel(SpaceAndTimeMVC.CONFIG_DATA_MODEL);
//    private List<BedType> bedTypes = new LinkedList<BedType>();
    private BedType selectedBedType;

    @Override
    public void setSelectedItem(Object anItem)
    {
        if(anItem instanceof BedType)
        {
            selectedBedType = (BedType) anItem;
        }
    }

    @Override
    public Object getSelectedItem()
    {
        return selectedBedType;
    }

    @Override
    public int getSize()
    {
        if(configDataModel != null)
        {
            List<BedType> bt = configDataModel.getBedTypes(false);
            if(bt != null)
            {
                return bt.size();
            }
            else
            {
                return 0;
            }
        }
        else
        {
            return 0;
        }
    }

    @Override
    public Object getElementAt(int index)
    {
        if(configDataModel != null)
        {
            List<BedType> bt = configDataModel.getBedTypes(false);
            if((bt != null) && (!bt.isEmpty()))
            {
                return bt.get(index);
            }
            else
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }

    @Override
    public void addListDataListener(ListDataListener l)
    {

    }

    @Override
    public void removeListDataListener(ListDataListener l)
    {
        
    }
}
